package com.group01.web.controller;

import com.group01.pojo.EsLog;
import com.group01.result.PageTemplate;
import com.group01.result.Result;
import com.group01.service.EsLogService;
import com.group01.vo.Log.LogGetPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 日志模块 - 插拔式 - 对已经写好的业务代码不能做出改变
 * @Author 翟玉龙
 * @Date 2024/6/25
 */
@RestController
@RequestMapping("/log")
@Api(tags = "日志模块")
@Validated
public class EsLogController {

    /**
     * 注入
     */
    private final EsLogService esLogService;

    public EsLogController(EsLogService esLogService) {
        this.esLogService = esLogService;
    }

    /**
     * 分页+条件查询日志信息
     * @param pageNum 页码
     * @param pageSize 页面大小
     * @param username 操作人用户名
     * @return {@link Result }<{@link List }<{@link EsLog }>>
     */
    @ApiOperation("分页+条件查询日志信息")
    @GetMapping("/getLogPage")
    public Result<PageTemplate<LogGetPageVO>> getLogPage(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
            @RequestParam(value = "username", required = false) String username
    ) {
        return esLogService.getLogPage(pageNum,pageSize,username);
    }

    /**
     * 删除+批量删除日志信息
     * @param ids 日志id集合
     * @return {@link Result }<{@link String }>
     */
    @ApiOperation("删除+批量删除日志信息")
    @DeleteMapping("/deleteLog/{ids}")
    public Result<String> deleteLog(@PathVariable("ids") String ids) {
        return esLogService.deleteLog(ids);
    }
}
